Here is a website link to query linux commands.
create new user with home folder
1
adduser XXX
sudo privilege:
vim /etc/sudoers
and add$username ALL=(ALL) ALL
at the bottom.start ssh on the server, the default port is 22
1
2sudo apt-get install openssh-server
sudo/etc/init.d/ssh startlist
1
2
3list -a #including hidden files
list -S #arrange by size
list -t #arrange by timeview text
1
2
3cat
head/tail -n 10 tmp.txt #view the first/last 10 lines
less #more powerful than moreChange the privilege
1
2chmod 777 ./
chmod a+x ./Check disk or file size
1
2df -h
du ./ --max-depth 2 -hCompress or uncompress files, refer to this link.
Grep + regular expression
1
grep [xyz]
Search file
1
2
3
4
5locate "keyword" #fast
find ./ -maxdepth 1 -name "*keyword*"
find ./ -name "*keyword*" -size +50M -size -100M
find ./ -name "*keyword*" -mmin -10 #m:modify min:minute
find ./ -name "*keyword*" -exec rm -r {} \;Pipe commands
1
2
3ls -l | tr -s ' ' | cut -d ' ' -f 2 #tr to truncate space
ls -l | sort -rnk2 #-r:reverse -n:numerical -k:k-th column
ls -l | wc -l #count linexargs:
1
2
3cat python/requirements.txt | xargs -L 1 sudo pip install
find . -name "*.c" | xargs rm -rf
find . -name '*.c' | xargs grep 'stdlib.h'alias: temporary alias command
1
2alias lnew="cd /home/niuli/caffe"
unalias lnewexport: The export command is one of the bash shell built-in commands, which means it is part of your shell.
1
2
3
4
5
6export a=linux.com
echo $a
export -n a #remove variable
printname () { echo "Linuxcareer.com"; }
export -f printname #export functionadd LD_LIBRARY_PATH
1
2echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/lib' >> ~/.bashrc
source ~/.bashrcshellscript sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25!/bin/bash
read -p "Please input your first name: "
echo -e "\nYour full name is: $firstname $lastname"
test ! -e $filename && echo "The filename '$filename' DO NOT exist" && exit 0
test -f $filename && filetype="regulare file"
test -d $filename && filetype="directory"
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
echo "OK, continue"
elif [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
echo "Oh, interrupt!"
else
echo "I don't know what your choice is"
fi
while [ "$yn" != "yes" -a "$yn" != "YES" ]
do
read -p "Please input yes/YES to stop this program: " yn
done
for animal in dog cat elephant
do
echo "There are ${animal}s.... "
done